package mx.edu.uteq.modelo.configuration;

import java.sql.Connection;
import java.sql.DriverManager;


public class ServiceLocator {
	private static ServiceLocator instance;
	private Connection MY_SQL_Connetion;
	
	
	public ServiceLocator(){
		cargaServicios();
	}
	
	
	public static ServiceLocator  getInstance(){
		if(instance== null){
			synchronized (ServiceLocator.class){
				if(instance==null){
					instance= new ServiceLocator();
				}
			}
		}
		return instance;
	}
	
	private void cargaServicios(){
		System.out.println("ServiceLocator..........................execute");
		System.out.println("Cargando servicios de mySQL");
		StringBuilder URL= new StringBuilder();
		try {
			
			
			Class.forName("com.mysql.jdbc.Driver");
			
			URL.append("jdbc")
			.append(":")
			.append("mysql")
			.append(":")
			.append("//")
			.append("localhost")
			.append(":")
			.append("3306")
			.append("/")
			.append("practicaMVC");
			System.out.println("URL ConectionString---->"+ URL.toString());
			this.MY_SQL_Connetion=DriverManager.getConnection(URL.toString(),"root","12345");
			System.out.println("mySQL Conection..........................[Establecida OK]");
		}catch (ClassNotFoundException  error) {
			System.out.println("(ServiceLocator.cargaServicios): Error---->"+error.getMessage());
		} catch (Exception error) {
			System.out.println("(ServiceLocator.cargaServicios): Error---->"+error.getMessage());
		}
	
	}

	/**
	 * getMY_SQL_Connetion
	 * regresa la conexion activa para My_SQL_ en la instancia de practicaMVC
	 * @return Connection
	 */
	public Connection getMY_SQL_Connetion() {
		return MY_SQL_Connetion;
	}
	
	
}
